#pragma once
#include <stdio.h>
#include <stdlib.h>
#include "sm2.h"
#include "base64.h"
void iPublicFunction(FILE * fp, char* publicBase64CharX, char* publicBase64CharY) {
	if(fp){

	fputs("These are the PublicKeyX and PublicKeyY which is divided by \n .(Base64 encoded)", fp);
	fputs("-----BEGIN CERTIFICATE-----", fp);
	fputc('\n', fp);
	for (int m = 0; m < 44; m++)
	{
		fputc(publicBase64CharX[m], fp);
	}
	fputc('\n', fp);
	for (int m = 0; m < 44; m++)
	{
		fputc(publicBase64CharY[m], fp);
	}
	fputc('\n', fp);
    fputs("-----END CERTIFICATE-----", fp);
	}
	else
	{
		printf("file not exist!");
	}
}
void iPublicFunctionRead(FILE * fp, char* publicBase64CharX, char* publicBase64CharY) {
	if (fp) {
		char* buff = (char*)malloc(1024);
		fgets(buff, 1024, fp);
		fgets(buff, 1024, fp);
		fgets(publicBase64CharX, 44, fp);
		fgets(publicBase64CharY, 44, fp);
		printf("Public Key Read ends successfully!\n");
	}
	else
	{
		printf("file not exist!");
	}
}

void iPrivateFunction(FILE * fp, char* privateBase64Char) {
	if (fp) {

		fputs("This the PrivateKey .(Base64 encoded)", fp);
		fputs("-----BEGIN CERTIFICATE-----", fp);
		fputc('\n', fp);
		for (int m = 0; m < 44; m++)
		{
			fputc(privateBase64Char[m], fp);
		}
		fputc('\n', fp);
		fputs("-----END CERTIFICATE-----", fp);
	}
	else
	{
		printf("file not exist!");
	}
}
void iPrivateFunctionRead(FILE * fp, char* privateBase64Char) {
	if (fp) {
		char* buff = (char*)malloc(1024);
		fgets(buff, 1024, fp);
		fgets(privateBase64Char, 44, fp);
		printf("Private Key Read ends successfully!\n");
	}
	else
	{
		printf("file not exist!");
	}
}